package com.duoduo.excel;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import jxl.*;
import jxl.write.*;
import jxl.write.Number;
import jxl.write.biff.RowsExceededException;

public class Excel {
	public void test(String[] head) throws IOException, RowsExceededException, WriteException {
		WritableWorkbook workbook = Workbook.createWorkbook(new File(
				"output.xls"));
		WritableSheet sheet = workbook.createSheet("First Sheet", 0);
		
		Label label;
		int N = head.length;
		for(int i=0; i< N; i++){
			//第一个坐标为X
			label= new Label(i, 0, head[i]); 
			sheet.addCell(label);
		}
		//M为对象数目
		int M = N*2;
		for(int i = 1; i <= M ;i++){
			for(int j =0; j< N; j++){
				//X坐标:0~N
				label= new Label( j,i, head[j]+" :"+j+" - "+i); 
				sheet.addCell(label);
			}
		}
		

		workbook.write(); 
		workbook.close();
	}
	public static void main(String args[]){
		Excel excel = new Excel();
		String[] head = {"A","B","C","D","F","G","H",};
		try {
			excel.test(head);
		} catch (RowsExceededException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WriteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
